package com.carbonxsilicon.travellersbuddy;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class ImageAdapter extends BaseAdapter {
    private Context mContext;

    public ImageAdapter(Context c) {
        mContext = c;
    }

    public int getCount() {
        return mThumbIds.length;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        RelativeLayout gridView;
        ImageView imageView;
        TextView textView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            //gridView = new View(mContext);

            // get layout from adapter_image.xml
            gridView = (RelativeLayout) inflater.inflate(R.layout.adapter_image, null);

            // set value into textview
            textView = (TextView) gridView
                    .findViewById(R.id.grid_item_label1);
                textView.setText(mThumbIds[position]);


            textView = (TextView) gridView
                    .findViewById(R.id.grid_item_label2);
            textView.setText("" + position);
            //textView.setText("xxx");

            // set image based on selected text
            imageView = (ImageView) gridView
                    .findViewById(R.id.grid_item_image);

            imageView.setImageResource(mThumbIds[position]);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            gridView.setPadding(2, 2, 2, 2);
        } else {
            //imageView = (ImageView) convertView;
            gridView = (RelativeLayout) convertView;
        }

        return gridView;
    }

    // references to our images
    private Integer[] mThumbIds = {
            R.drawable.sample_0, R.drawable.sample_1,
            R.drawable.sample_2, R.drawable.sample_3,
            R.drawable.sample_4,
    };
}